﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading;

namespace YouTubeDownloader
{
    class Program
    {
        
        static void Main(string[] args)
        {
            // Synchronous example
            // Downloader downloader = new Downloader();
            // downloader.DownloadVideo(new Uri("http://www.youtube.com/watch?v=tPEE9ZwTmy0"));




            // Asynchronous example
            Downloader downloader = new Downloader();
            downloader.DownloadVideoProgressChanged += new EventHandler<DownloadVideoProgressChangedEventArgs>(downloader_DownloadVideoProgressChanged);
            downloader.DownloadVideoAsync(new Uri("http://www.youtube.com/watch?v=PWUcIn1GGmE"), @"c:\temp");

            while (downloader.IsBusy)
                Thread.CurrentThread.Join(TimeSpan.FromSeconds(3));


        }

        static void downloader_DownloadVideoProgressChanged(object sender, DownloadVideoProgressChangedEventArgs e)
        {
            Debug.WriteLine("{0:0.0}% at {1} bps", e.PercentageComplete, e.Speed);
        }

        

        
    }
}
